home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / Shell ƒ / launch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.0 KB  |  113 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        launch.c
  4.  
  5. Purpose:    This module handles launching another application.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "launch.h"
  25. #include "file interface.h"
  26.  
  27. #define haveAUX() 0
  28.  
  29. /*-----------------------------------------------------------------------------------*/
  30. /* internal stuff for launch.c                                                       */
  31.  
  32. void DoLaunch(Ptr theApp, short memCode );
  33. void PathNameFromDirID(long dirID, short vRefNum, Str255 fullPathName);
  34. void pstrcat(Str255 dst, Str255 src);
  35. void pstrinsert(Str255 dst, Str255 src);
  36.  
  37.  
  38. void LaunchDispatch(void)
  39. {
  40.     FSSpec                temp;
  41.  
  42.     if (GetSourceFile(&temp, FALSE, TRUE))
  43.     {
  44.         PathNameFromDirID(temp.parID, temp.vRefNum, temp.name);
  45.         DoLaunch((Ptr)temp.name,  0 );            /* launch the program */
  46.     }
  47. }
  48.  
  49. void DoLaunch(Ptr theApp, short memCode )
  50. {
  51.     struct {                /* temporary structure */
  52.         Ptr    appName;    /* the name of the launchee */
  53.         short    memUse;        /* config. param. see above Notes */
  54.         char    lc[2];            /* extended parameters */
  55.         long    extBlocLen;    /* # bytes in extension(6) */
  56.         short    fFlags;    /* Finder file info flags */
  57.         long    launchFlags;    /* bit 31,30==1 for sublaunch */
  58.     } LaunchRec;
  59.  
  60.     LaunchRec.appName = theApp;
  61.     LaunchRec.launchFlags = memCode;
  62.     asm {
  63.             lea    LaunchRec, A0
  64.             _Launch
  65.     }
  66. }
  67.  
  68. void pstrcat(Str255 dst, Str255 src)
  69. {
  70.     /* copy string in */
  71.     BlockMove(src + 1, dst + *dst + 1, *src);
  72.     /* adjust length byte */
  73.     *dst += *src;
  74. }
  75.  
  76. void pstrinsert(Str255 dst, Str255 src)
  77. {
  78.     /* make room for new string */
  79.     BlockMove(dst + 1, dst + *src + 1, *dst);
  80.     /* copy new string in */
  81.     BlockMove(src + 1, dst + 1, *src);
  82.     /* adjust length byte */
  83.     *dst += *src;
  84. }
  85.  
  86. void PathNameFromDirID(long dirID, short vRefNum, Str255 fullPathName)
  87. {
  88.     DirInfo    block;
  89.     Str255    directoryName;
  90.     OSErr    err;
  91.  
  92.     block.ioDrParID = dirID;
  93.     block.ioNamePtr = directoryName;
  94.     do
  95.     {
  96.         block.ioVRefNum = vRefNum;
  97.         block.ioFDirIndex = -1;
  98.         block.ioDrDirID = block.ioDrParID;
  99.         err = PBGetCatInfo((CInfoPBPtr)&block, FALSE);
  100.         if (haveAUX())
  101.         {
  102.             if (directoryName[1] != '/')
  103.                 pstrcat(directoryName, (StringPtr)"\p/");
  104.         }
  105.         else
  106.         {
  107.             pstrcat(directoryName, (StringPtr)"\p:");
  108.         }
  109.         pstrinsert(fullPathName, directoryName);
  110.     }
  111.     while (block.ioDrDirID != 2);
  112. }
  113.